package com.jz.netthings.application.sample.controller;


import com.jz.netthings.application.sample.bean.AssayPrintSupport;
import com.jz.netthings.application.sample.bean.PlasmaSamples;
import com.jz.netthings.application.sample.service.PlasmaSamplesService;
import com.jz.netthings.bean.system.JyUser;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.security.utils.Token;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.system.utils.AdscmSystemUtils;
import com.jz.netthings.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lzf
 * @since 2019-03-12
 */
@RestController
@RequestMapping("adscm/application/plasmaSamples")
public class PlasmaSamplesController {
@Autowired
    PlasmaSamplesService plasmaSamplesService;
@Autowired
RedisTemplate<Object, Token> tokenRedisTemplate;

    /**
     * 默认查询当天的
     * @param currentPage
     * @param pageSize
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("query")
    public SimpleCoreResponse query(@RequestParam("currentPage") Integer currentPage,
                                    @RequestParam("pageSize") Integer pageSize) throws AdscmSystemException{
//        return new SimpleCoreResponse("200","查询成功",plasmaSamplesService.queryAll(currentPage,pageSize));
        return new SimpleCoreResponse("200","查询成功",plasmaSamplesService.queryCurrentDays(currentPage,pageSize));
    }
    @RequestMapping("queryByNameAndNo")
    public  SimpleCoreResponse queryByNameAndNo(@RequestParam("currentPage") Integer currentPage,
                                                @RequestParam("pageSize") Integer pageSize,
                                                String name,String smallNo,String type,String time) throws AdscmSystemException {
        return new SimpleCoreResponse("200","查询成功",plasmaSamplesService.queryByNameAndNo(name,smallNo,currentPage,pageSize,type,time));
    }

    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody PlasmaSamples plasmaSamples, HttpServletRequest request) throws AdscmSystemException {

        String tokenId = request.getParameter("tokenId");
        JyUser user = AdscmBaseUtils.getInstance().getUser(tokenId, tokenRedisTemplate);
        return new SimpleCoreResponse("200","修改成功",plasmaSamplesService.updateAll(plasmaSamples,user));
    }
//    @RequestMapping("update")
//    public SimpleCoreResponse update(String plasmaSamples, HttpServletRequest request) throws AdscmSystemException {
//
//        String tokenId = request.getParameter("tokenId");
//        JyUser user = AdscmBaseUtils.getInstance().getUser(tokenId, tokenRedisTemplate);
//        return new SimpleCoreResponse("200","修改成功",plasmaSamplesService.updateAll(plasmaSamples,user));
//    }
    @RequestMapping("selectPlasmaSampleByProviderNo/{probiderNo}")
    public SimpleCoreResponse selectPlasmaSampleByProviderNo(@PathVariable String probiderNo)throws AdscmSystemException{
      PlasmaSamples plasmaSamples= plasmaSamplesService.selectPlasmaSampleByProviderNo(probiderNo);
        return new SimpleCoreResponse("200","修改成功",plasmaSamples);
    }

    /**
     * 查询血红蛋白含量，根据日期，用于报表打印
     * @param date
     * @param printType 打印类型 1：血红蛋白含量，2：血红蛋白检测，3：化检记录表
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/selectPrintList")
    public SimpleCoreResponse selectPrintList(String date,int printType)throws AdscmSystemException{
        AssayPrintSupport assayPrintSupport = plasmaSamplesService.selectPrintList(date,printType);
        return new SimpleCoreResponse("200","查询成功",assayPrintSupport);
    }


}

